package com.itheima.test1;

import java.util.Random;
import java.util.Scanner;

public class Test7 {
    public static void main(String[] args) {
        //双色球系统
        //投注号由6个红球号码哈一个蓝色号码组成
        //红色号码从1-33中选择；
        //蓝色求号码从1-16中选择
        // 中奖条件和奖金表
        //一等奖 六红一蓝 最高1000万
        //二等奖 六红 最高500万
        //三等奖 五红一蓝 3000
        //四等奖 五红 四红一蓝 200
        //五等奖 四红 三红一蓝 两红一蓝 10
        //六等奖 一篮 一红一蓝 5

        //创建出中奖号码六个红球号码，一个蓝球号码
        int[] nums = new int[7];
        Random r = new Random();
        for (int i = 0; i < 6; i++) {
            int x = r.nextInt(33) + 1;
            if (!contains(nums, x)) {
                nums[i] = x;
            }
        }
        int bluenum = r.nextInt(16) + 1;
        nums[6] = bluenum;
        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i] + " ");
        }

        //输入猜的红球号码
        Scanner sc = new Scanner(System.in);

        int[] scnums = new int[7];
        for (int i = 0; i < 6; ) {
            System.out.println("请输入第" + (i + 1) + "个红球号码");
            int num = sc.nextInt();
            if (num < 1 || num > 33) {
                System.out.println("输入号码超出范围请重新输入");
            } else {
                if(!contains(scnums,num)) {
                    scnums[i] = num;
                    i++;
                }else{
                    System.out.println("输入无效号码");
                }
            }
        }
        System.out.println("/");

        //输入猜的蓝球号码
        while (true) {
            System.out.println("请输入蓝球号码");
            int num = sc.nextInt();
            if (num < 1 && num > 16) {
                System.out.println("输入号码超出范围请重新输入");
            } else {
                scnums[6] = num;
                break;
            }
        }

        //来判断是否中奖
        int count = 0;
        //int[] alestimate = new int[6];

        //当蓝球号码没猜中时
        if (nums[6] != scnums[6]) {

            //统计红球号码猜中的数量
            for (int i = 0; i < scnums.length - 1; i++) {
                if (contains(nums, scnums[i])) {
                    count++;
                    //       alestimate[i] = scnums[i];
                }
            }


            switch (count) {
                case 1 - 3:
                    System.out.println("很可惜你没中奖");
                    break;
                case 4:
                    System.out.println("恭喜你获得五等奖10元");
                    break;
                case 5:
                    System.out.println("恭喜你获得四等奖200元");
                    break;
                case 6:
                    System.out.println("恭喜你获得二等奖最高500万元");
                    break;
            }

            //当蓝球号码猜中时
        } else {
            for (int i = 0; i < scnums.length - 1; i++) {
                if (contains(nums, scnums[i])) {
                    count++;
                    //       alestimate[i] = scnums[i];
                }
            }
            switch (count) {
                case 0:
                    System.out.println("恭喜你获得六等奖5元");
                    break;
                case 1:
                    System.out.println("恭喜你获得六等奖5元");
                    break;
                case 2:
                    System.out.println("恭喜你获得五等奖10元");
                    break;
                case 3:
                    System.out.println("恭喜你获得五等奖10元");
                    break;
                case 4:
                    System.out.println("恭喜你获得四等奖200元");
                    break;
                case 5:
                    System.out.println("恭喜你获得三等奖3000元");
                    break;
                case 6:
                    System.out.println("恭喜你获得一等奖最高1000万元");
                    break;
            }
        }


    }

    //判断该号码是否在数组中
    public static boolean contains(int[] nums, int target) {
        for (int i = 0; i < nums.length - 1; i++) {
            if (nums[i] == target) {
                return true;
            }
        }
        return false;

    }


}
